home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ADA Programming Guide
/
ADA Programming Guide.iso
/
adatutor
/
lrmrdr
/
make_cit.a
< prev
next >
Wrap
Text File
|
1996-01-30
|
12KB
|
335 lines
-- Make_CIT by Rick Conn
-- Scan Ada LRM Chapter Files for section numbers and extract them
-- into a file. Then use that file to build the CIT.ADA file,
-- which is the source to package CIT.
-- COPYRIGHT NOTICE
-- Ada LRM Reader - Interactive Presentation of the Ada LRM
-- Copyright (C) 1992 Richard Conn
--
-- This program is free software; you can redistribute it
-- and/or modify it under the terms of the GNU General Public
-- License Version 1 as published by the Free Software
-- Foundation.
--
-- This program is distributed in the hope that it will be
-- useful, but WITHOUT ANY WARRANTY; without even the implied
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-- PURPOSE. See the GNU General Public License for more
-- details. You should have received a copy of the GNU General
-- Public License along with this program; if not, write to the
-- Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
-- 02139, USA. See the ABOUT screens for further information,
-- including information on how to contact the author.
with SYSDEP;
with DAF_Handler;
with Output_File; -- CS Parts
with Console; -- CS Parts
procedure Make_CIT is
use DAF_Handler; -- for equality and inequality tests
subtype FN_STRING is STRING(1..10);
type FN_VECTOR is array (NATURAL range <>) of FN_STRING;
File_Names : constant FN_VECTOR := (
"chap01.daf", "chap02.daf", "chap03.daf", "chap04.daf",
"chap05.daf", "chap06.daf", "chap07.daf", "chap08.daf",
"chap09.daf", "chap10.daf", "chap11.daf", "chap12.daf",
"chap13.daf", "chap14.daf", "chapaa.daf", "chapab.daf",
"chapac.daf", "chapad.daf", "chapae.daf", "chapaf.daf"
);
subtype FILE_ID_STRING is STRING (1..2);
type CITATION_RECORD is record
Citation_ID : STRING(1..20);
Citation_ID_Last : NATURAL;
File_ID : FILE_ID_STRING;
Start : DAF_Handler.LINE_NUMBER;
Stop : DAF_Handler.LINE_NUMBER;
end record;
type CITATION_RECORD_VECTOR is
array (1..SYSDEP.Total_Number_of_Citations) of CITATION_RECORD;
CRV : CITATION_RECORD_VECTOR;
Next_CRV : DAF_Handler.LINE_NUMBER := 1;
Package_File_Name : constant STRING := "CIT.ADA";
Output_File_ID : Output_File.FILE_TYPE;
----------------------------------------------------------------
-- Set Citation_ID and Citation_ID_Last fields of CRV(Next_CRV)
procedure Set_Citation_ID (Item : in STRING;
File_ID : in STRING) is
begin -- Set_Citation_ID
CRV(Next_CRV).Citation_ID(1..Item'LENGTH) := Item;
CRV(Next_CRV).Citation_ID_Last := Item'LENGTH;
CRV(Next_CRV).File_ID := File_ID;
end Set_Citation_ID;
----------------------------------------------------------------
-- Make entry of the form CITATION,chn,m where CITATION is the
-- citation name, ch is the last 2 character in the chapter name,
-- n is the 1st line number, and m is the last line number
procedure Process_File (Name : in STRING) is
Inline : DAF_Handler.LINE;
Line_Number : NATURAL := 0;
First_Time : BOOLEAN := TRUE;
Input_File : DAF_Handler.DAF_ID;
Start_Col : NATURAL;
Stop_Col : NATURAL;
begin -- Process_File
Console.Put_Line ("Processing File " & Name);
Input_File := DAF_Handler.Open (Name);
-- loop until end of input file
while not DAF_Handler.Is_End_of_File (Input_File) loop
Inline := DAF_Handler.Read_Next (Input_File);
Line_Number := Line_Number + 1;
-- process a new section
if Inline.Kind = DAF_Handler.SECTION then
-- close out entry for old section if not the first time
if not First_Time then
CRV(Next_CRV).Stop := Line_Number - 1;
Next_CRV := Next_CRV + 1;
end if;
First_Time := FALSE;
-- find start of section citation
Start_Col := 0;
for I in 1 .. Inline.Str_Last loop
if Inline.Str(I) > ' ' then
Start_Col := I;
exit;
end if;
end loop;
-- check for error
if Start_Col > 0 then
-- find end of section citation
for I in Start_Col .. Inline.Str_Last loop
if Inline.Str(I) <= ' ' then
Stop_Col := I-1;
exit;
end if;
Stop_Col := I;
end loop;
-- change dots in section citation to P's
for I in Start_Col .. Stop_Col loop
if Inline.Str(I) = '.' then
Inline.Str(I) := 'P';
end if;
end loop;
-- strip off trailing P if any
if Inline.Str(Stop_Col) = 'P' then
Stop_Col := Stop_Col - 1;
end if;
-- start entry for section citation
Set_Citation_ID('C' & Inline.Str(Start_Col..Stop_Col),
Name(Name'FIRST+4 .. Name'FIRST+5));
CRV(Next_CRV).Start := Line_Number;
end if; -- error check
end if; -- section processing
end loop;
-- close out last citation if any
if not First_Time then
CRV(Next_CRV).Stop := Line_Number;
Next_CRV := Next_CRV + 1;
end if;
-- close input file but leave output file open for next pass
DAF_Handler.Close (Input_File);
exception -- Process_Line
when DAF_Handler.FILE_NOT_FOUND =>
Console.Put_Line (" File not found");
when DAF_Handler.NO_DAF_OPEN =>
Console.Put_Line (" File not open");
when DAF_Handler.READ_ERROR =>
Console.Put_Line (" Read error on file");
when DAF_Handler.STACK_OVERFLOW =>
Console.Put_Line (" Stack overflow");
when others =>
Console.Put_Line (" Unexpected Error");
end Process_File;
----------------------------------------------------------------
-- Make entry of the form Enum,ch1,m where Enum is the
-- citation name, ch is the last 2 characters in the chapter name,
-- 1 is the 1st line number, and m is the last line number
procedure Count_Lines (Name : in STRING; Enum : in STRING) is
Inline : DAF_Handler.LINE;
Input_File : DAF_Handler.DAF_ID;
Line_Number : NATURAL := 0;
begin -- Count_Lines
Console.Put_Line ("Processing File " & Name);
Input_File := DAF_Handler.Open (Name);
-- loop over file, counting lines
while not DAF_Handler.Is_End_of_File (Input_File) loop
Inline := DAF_Handler.Read_Next (Input_File);
Line_Number := Line_Number + 1;
end loop;
-- store results and close input file
Set_Citation_ID (Enum, Name(Name'FIRST+4 .. Name'FIRST+5));
CRV(Next_CRV).Start := 1;
CRV(Next_CRV).Stop := Line_Number;
Next_CRV := Next_CRV + 1;
DAF_Handler.Close (Input_File);
exception
when DAF_Handler.FILE_NOT_FOUND =>
Console.Put_Line (" File not found");
when DAF_Handler.NO_DAF_OPEN =>
Console.Put_Line (" File not open");
when DAF_Handler.READ_ERROR =>
Console.Put_Line (" Read error on file");
when DAF_Handler.STACK_OVERFLOW =>
Console.Put_Line (" Stack overflow");
when others =>
Console.Put_Line (" Unexpected Error");
end Count_Lines;
begin -- Make_CIT
Console.Put_Line (Package_File_Name & " File Builder");
for I in SYSDEP.Intro_Copyright_Notice'RANGE loop
Console.Put_Line (SYSDEP.Intro_Copyright_Notice(I));
end loop;
-- Build CRV array
for I in File_Names'RANGE loop
Process_File (File_Names(I));
end loop;
Count_Lines ("chapco.daf", "CONTENTS");
Count_Lines ("chapfo.daf", "FOREWARD");
Count_Lines ("chapin.daf", "INDEX");
Count_Lines ("chappo.daf", "POSTSCRIPT");
Count_Lines ("chaphe.daf", "HELP");
Count_Lines ("chapxx.daf", "ABOUT");
-- Create the Package file
Output_File.Create (Output_File_ID, Package_File_Name);
-- Part 1 -- Build CITATION enumerated type
-- Output specification of package
Output_File.Put_Line (Output_File_ID, "with DAF_Handler;");
Output_File.Put_Line (Output_File_ID, "package Citation_Definition is");
Output_File.New_Line (Output_File_ID);
-- Output enumeration type CITATION
Output_File.Put_Line (Output_File_ID, " type CITATION_ID is (");
for I in 1 .. Next_CRV-1 loop
Output_File.Put_Line (Output_File_ID, " " &
CRV(I).Citation_ID(1..CRV(I).Citation_ID_Last) & ",");
end loop;
Output_File.Put_Line (Output_File_ID,
" ERROR,");
Output_File.Put_Line (Output_File_ID,
" -- Commands for immediate execution");
Output_File.Put_Line (Output_File_ID,
" N, P,");
Output_File.Put_Line (Output_File_ID,
" USER_INPUT, PRINT, PS,");
Output_File.Put_Line (Output_File_ID,
" NEXT, PREVIOUS, PAUSE, PUSH, POP,");
Output_File.Put_Line (Output_File_ID,
" SEARCH_FIRST, SEARCH_NEXT, REFRESH,");
Output_File.Put_Line (Output_File_ID,
" QUIT");
Output_File.Put_Line (Output_File_ID,
" );");
Output_File.New_Line (Output_File_ID);
-- Part 2 - Build array of chapter and line indexes
-- Output text of CITATION_KEY record
Output_File.Put_Line (Output_File_ID,
" type CITATION_LOCATION is record");
Output_File.Put_Line (Output_File_ID,
" Chapter : STRING(1..2);");
Output_File.Put_Line (Output_File_ID,
" Start : DAF_Handler.LINE_NUMBER;");
Output_File.Put_Line (Output_File_ID,
" Stop : DAF_Handler.LINE_NUMBER;");
Output_File.Put_Line (Output_File_ID,
" end record;");
Output_File.New_Line (Output_File_ID);
-- Output text of type CITATION_LOCATION_VECTOR
Output_File.Put_Line (Output_File_ID,
" type CITATION_LOCATION_VECTOR is array (CITATION_ID) of");
Output_File.Put_Line (Output_File_ID, " CITATION_LOCATION;");
Output_File.New_Line (Output_File_ID);
-- Output vector CKV
Output_File.Put_Line (Output_File_ID,
" CLV : constant CITATION_LOCATION_VECTOR := (");
for I in 1 .. Next_CRV-1 loop
Output_File.Put_Line (Output_File_ID, " " &
CRV(I).Citation_ID(1..CRV(I).Citation_ID_Last) & " => (" &
'"' & CRV(I).File_ID & '"' & "," &
NATURAL'IMAGE(CRV(I).Start) & "," &
NATURAL'IMAGE(CRV(I).Stop) & "),");
end loop;
-- Output special cases of CKV
Output_File.Put_Line (Output_File_ID,
" ERROR => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" N => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" P => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" USER_INPUT => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" PRINT => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" PS => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" NEXT => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" PREVIOUS => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" PAUSE => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" PUSH => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" POP => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" SEARCH_FIRST => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" SEARCH_NEXT => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" REFRESH => (" & '"' & " " & '"' & ", 1, 1),");
Output_File.Put_Line (Output_File_ID,
" QUIT => (" & '"' & " " & '"' & ", 1, 1)");
Output_File.Put_Line (Output_File_ID, " );");
-- Close output file
Output_File.New_Line (Output_File_ID);
Output_File.Put_Line (Output_File_ID, "end Citation_Definition;");
Output_File.Close (Output_File_ID);
Console.Put_Line ("File " & Package_File_Name & " created");
end Make_CIT;